import 'dart:ui';

import 'package:flutter/material.dart';

///绘制5子棋
class CustomPaintRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: CustomPaint(
        painter: ChessPainter(),
        child: Container(
          padding: EdgeInsets.only(left: 20),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Text('哈哈'),
              Text('哈哈哈'),
              Text('哈哈哈哈哈'),
              Text('哈哈哈哈哈'),
              Text('哈哈哈哈哈'),
              Text('哈哈哈哈哈'),
              Text('哈哈哈哈哈'),
              Text('哈哈哈哈哈'),
            ],
          ),
        ),
      ),
    );
  }

}

class ChessPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    print('height---${size.height}');
    Paint paint = Paint()
      ..isAntiAlias = true //抗锯齿
      ..style = PaintingStyle.fill //设置画笔为填充模式
      ..color = Color(0x77cdb175);
    //注意 Offset.zero & size 这里是重载操纵符
    //等同于  new Rect.fromLTWH(0.0, 0.0, size.width, size.height)
    canvas.drawRect(Offset.zero & size, paint);
    paint
      ..color = Colors.red[200];
    canvas.drawCircle(Offset(4, 4), 4, paint);

    paint
      ..style = PaintingStyle.stroke
      ..color = Colors.grey
      ..strokeWidth = 1.5;

    //尝试画虚线
    List<Offset> points = [];
    double currentHeight = 10;
    while(currentHeight < size.height) {
      points.add(Offset(4, currentHeight));
      currentHeight = currentHeight + 8;
    }

    canvas.drawPoints(PointMode.points, points, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }

}